/*     */ package com.cr.common.utils.html;
/*     */ 
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ 
/*     */ public class EscapeUtil {
/*     */   public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
/*     */   
/*  14 */   private static final char[][] TEXT = new char[64][];
/*     */   
/*     */   static {
/*  18 */     for (int i = 0; i < 64; i++) {
/*  20 */       (new char[1])[0] = (char)i;
/*  20 */       TEXT[i] = new char[1];
/*     */     } 
/*  24 */     TEXT[39] = "&#039;".toCharArray();
/*  25 */     TEXT[34] = "&#34;".toCharArray();
/*  26 */     TEXT[38] = "&#38;".toCharArray();
/*  27 */     TEXT[60] = "&#60;".toCharArray();
/*  28 */     TEXT[62] = "&#62;".toCharArray();
/*     */   }
/*     */   
/*     */   public static String escape(String text) {
/*  39 */     return encode(text);
/*     */   }
/*     */   
/*     */   public static String unescape(String content) {
/*  50 */     return decode(content);
/*     */   }
/*     */   
/*     */   public static String clean(String content) {
/*  61 */     return (new HTMLFilter()).filter(content);
/*     */   }
/*     */   
/*     */   private static String encode(String text) {
/*     */     int len;
/*  73 */     if (text == null || (len = text.length()) == 0)
/*  75 */       return ""; 
/*  77 */     StringBuilder buffer = new StringBuilder(len + (len >> 2));
/*  79 */     for (int i = 0; i < len; i++) {
/*  81 */       char c = text.charAt(i);
/*  82 */       if (c < '@') {
/*  84 */         buffer.append(TEXT[c]);
/*     */       } else {
/*  88 */         buffer.append(c);
/*     */       } 
/*     */     } 
/*  91 */     return buffer.toString();
/*     */   }
/*     */   
/*     */   public static String decode(String content) {
/* 102 */     if (MyStringUtils.isEmpty(content))
/* 104 */       return content; 
/* 107 */     StringBuilder tmp = new StringBuilder(content.length());
/* 108 */     int lastPos = 0, pos = 0;
/* 110 */     while (lastPos < content.length()) {
/* 112 */       pos = content.indexOf("%", lastPos);
/* 113 */       if (pos == lastPos) {
/* 115 */         if (content.charAt(pos + 1) == 'u') {
/* 117 */           char c = (char)Integer.parseInt(content.substring(pos + 2, pos + 6), 16);
/* 118 */           tmp.append(c);
/* 119 */           lastPos = pos + 6;
/*     */           continue;
/*     */         } 
/* 123 */         char ch = (char)Integer.parseInt(content.substring(pos + 1, pos + 3), 16);
/* 124 */         tmp.append(ch);
/* 125 */         lastPos = pos + 3;
/*     */         continue;
/*     */       } 
/* 130 */       if (pos == -1) {
/* 132 */         tmp.append(content.substring(lastPos));
/* 133 */         lastPos = content.length();
/*     */         continue;
/*     */       } 
/* 137 */       tmp.append(content.substring(lastPos, pos));
/* 138 */       lastPos = pos;
/*     */     } 
/* 142 */     return tmp.toString();
/*     */   }
/*     */   
/*     */   public static void main(String[] args) {
/* 147 */     String html = "<script>alert(1);</script>";
/* 151 */     System.out.println(clean(html));
/* 152 */     System.out.println(escape(html));
/* 153 */     System.out.println(unescape(html));
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\html\EscapeUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */